package com.wwwarehouse.financialcenter.adapter.moneyhouse;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wwwarehouse.common.tools.ImageloaderUtils;
import com.wwwarehouse.financialcenter.R;
import com.wwwarehouse.financialcenter.bean.bindingcard.BindCardBean;
import com.wwwarehouse.financialcenter.eventbus.CardInfoEvent;

import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * Description:
 * Copyright  : Copyright (c) 2017
 * Author     : yfwang
 * Date       : 2017/11/13 18:55
 */
public class CardListAdapter extends RecyclerView.Adapter<CardListAdapter.ViewHolder> {

    private Context mContext;
    private List<BindCardBean.DataBean.ListBean> list;

    public CardListAdapter(Context mContext, List<BindCardBean.DataBean.ListBean> list) {
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.financial_center_item_card_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        ImageloaderUtils.displayImg(list.get(position).getBankIconAn(), holder.mBankIcon);
        holder.mBankName.setText(list.get(position).getBankName());
        holder.mCardNumber.setText(String.format("**** **** **** %s", list.get(position).getCardNo()));
        holder.mListItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new CardInfoEvent(list.get(position)));
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView mBankIcon;
        private TextView mBankName;
        private TextView mCardNumber;
        private  LinearLayout mListItem;

        public ViewHolder(View view) {
            super(view);
            mBankIcon = (ImageView) view.findViewById(R.id.iv_bank_icon);
            mBankName = (TextView) view.findViewById(R.id.tv_bank_name);
            mCardNumber = (TextView) view.findViewById(R.id.tv_card_number);
            mListItem = (LinearLayout) view.findViewById(R.id.ll_listitem);
        }
    }
}
